function TreeNode(val, left, right) {
    this.val = (val === undefined ? 0 : val);
    this.left = (left === undefined ? null : left);
    this.right = (right === undefined ? null : right);
}

// 将数组转换为二叉树
function arrayToTree(arr) {
    if (arr.length === 0 || arr[0] === null) return null;

    const root = new TreeNode(arr[0]);
    const queue = [root];
    let i = 1;

    while (queue.length > 0 && i < arr.length) {
        const current = queue.shift();

        // 处理左子节点
        if (i < arr.length && arr[i] !== null) {
            current.left = new TreeNode(arr[i]);
            queue.push(current.left);
        }
        i++;

        // 处理右子节点
        if (i < arr.length && arr[i] !== null) {
            current.right = new TreeNode(arr[i]);
            queue.push(current.right);
        }
        i++;
    }

    return root;
}
let root = [543, 384, 652, null, 445, null, 699]
var getMinimumDifference = function (root) {
    const arr = []
    function inorder(root) {
        if (!root) {
            return
        }
        inorder(root.left)
        arr.push(root.val)
        inorder(root.right)
    }
    inorder(root)
    console.log(arr);

    return arr[1] - arr[0]
};
console.log(getMinimumDifference(arrayToTree(root)));
